﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;


public static class RenderExtension
{
    #region URP设置
    /// <summary>
    /// 设置基于URP UnLit的颜色
    /// </summary>
    /// <param name="renderer"></param>
    /// <param name="color"></param>
    public static void SetColor(this Renderer renderer, Color color)
    {
        renderer.material.SetColor("_BaseColor", color);
    }
    /// <summary>
    /// 获取基于URP UnLit的颜色
    /// </summary>
    /// <param name="renderer"></param>
    /// <returns></returns>
    public static Color GetColor(this Renderer renderer)
    {
        return renderer.material.GetColor("_BaseColor");
    }

    public static void SetSpriteRendererAlpha(this SpriteRenderer renderer, float alpha)
    {
        renderer.color = new Color(1, 1, 1, alpha);
    }

    public static void SetAlpha(this Renderer renderer, float alpha)
    {
        Color c = renderer.GetColor();
        renderer.material.SetColor("_BaseColor", new Color(c.r, c.g, c.b, alpha));
    }
    public static void ToAlpha(this Renderer renderer, float alpha, float durtion)
    {
        DG.Tweening.DOTween.ToAlpha(renderer.GetColor, v => renderer.SetColor(v), alpha, durtion);
    }

    public static void ToColor(this Renderer renderer, Color color, float durtion)
    {
        DG.Tweening.DOTween.To(renderer.GetColor, v => renderer.SetColor(v), color, durtion);
    }

    #endregion
    #region BuildIn设置
    /// <summary>
    /// 设置基于URP UnLit的颜色
    /// </summary>
    /// <param name="renderer"></param>
    /// <param name="color"></param>
    public static void SetColorBuildIn(this Renderer renderer, Color color)
    {
        renderer.material.color = color;
    }
    public static Color GetColorBuildIn(this Renderer renderer)
    {
        return renderer.material.color;
    }

    public static void SetAlphaBuildIn(this Renderer renderer, float alpha)
    {
        Color c = renderer.material.color;
        renderer.SetColorBuildIn(new Color(c.r, c.g, c.b, alpha));
    }
    public static void ToAlphaBuildIn(this Renderer renderer, float alpha, float durtion)
    {
        DG.Tweening.DOTween.ToAlpha(renderer.GetColorBuildIn, v => renderer.SetColorBuildIn(v), alpha, durtion);
    }
    #endregion
}

